/**
 * create by young (young2f@outlook.com) on 2020/12/4
 */
'use strict';
const model = require('../base/modelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    isRent: {
      type: Boolean, _type: 'boolean', title: '是否租用', enableArea: [],
      default: false
    },
    materialType: {
      type: 'string', _type: 'select', table: 'division', title: '材料类型', required: true, enableArea: [
        'table', 'input',
        'detail',
        'search'
      ],
      options: [ '主营业务采购', '其它采购' ]
    },
    division: {
      type: 'string', _type: 'select', table: 'division', title: '事业部', required: true, enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },

    vendor: {
      type: 'string', _type: 'string', title: '供应商名称', required: true, enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    vendorCode: {
      type: 'string', _type: 'code', title: '供应商编码', required: true, enableArea: []
    },
    materials: {
      type: Array, _type: 'code', title: '物料清单', required: true, enableArea: []
    },
    count: {
      type: 'number', _type: 'number', title: '数量', enableArea: [
        'table', 'input',
        'detail',
      ], default: 0
    },

    amount: {
      type: 'number', _type: 'number', title: '金额', enableArea: [
        'table', 'detail',
      ], default: 0
    },
    taxRate: {
      type: 'string', _type: 'select', title: '税率', enableArea: [
        'table', 'detail',
      ], default: '13%'
    },
    tax: {
      type: 'number', _type: 'code', title: '税额', enableArea: [
        'detail'
      ], default: 0
    },

    reviewStatus: {
      type: 'string', _type: 'string', title: '审核状态', disabled: true, enableArea: [
        'table', 'detail'
      ], default: '待审核'
    },
    acceptanceStatus: {
      type: String,
      _type: 'string',
      title: '验收状态',
      enableArea: [ 'table', 'search','detail' ],
      default: '待验收'
    },
    // payReviewStatus: {
    //   type: 'string', _type: 'string', title: '付款审核状态', disabled: true, enableArea: [
    //     'table', 'detail'
    //   ], default: '待审核'
    // },

    // inboundCount: {
    //   type: 'number', _type: 'number', title: '入库数量', disabled: true, enableArea: [
    //     'table', 'detail'
    //   ], default: 0
    // },
    // inboundDate: {
    //   type: Date, _type: 'date', title: '入库时间', disabled: true, enableArea: [],
    // },
    procureDate: {
      type: Date, _type: 'date', title: '采购日期', enableArea: [
        'table', 'detail'
      ],
    },
    rentStartDate: {
      type: Date, _type: 'date', title: '租用开始日期', enableArea: [
        'detail'
      ],
    },
    rentEndDate: {
      type: Date, _type: 'date', title: '租用结束日期', enableArea: [
        'detail'
      ],
    },
    fileList: {
      type: 'array', _type: 'array', title: 'PIC附件', enableArea: []
    },
    // invoiceFileList: {
    //   type: 'array', _type: 'array', title: '发票', enableArea: []
    // },
    pdfFileList: {
      type: 'array', _type: 'array', title: 'PDF', enableArea: []
    },
    isEnabled: { type: 'boolean' },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  _schema.index({ 'code': 1 });
  return connect.model('ProcureOrder', _schema);
};
